﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class TreeList :SkinnedGridView<CategoryInfo>
    {
        public TreeList()
        {
            IsOnlyEnable = true;
        }

        protected override IList<CategoryInfo> GridViewDataSourceHandler(int pageIndex, int pageSize, out int totalRecord)
        {
            IList<CategoryInfo> list=TreeTables.TreeTable(TreeType).GetModelsByParentId(ParentId, IsOnlyEnable, pageSize, pageIndex, out totalRecord);

            if (list.Count == 0 || Depth == 0)
                Visible = false;

            return list;
        }

        private int parentId = SiteContext.Current.CategoryId;
        public int ParentId
        {
            get { return parentId; }
            set { parentId = value; }
        }


        private TreeTableType _type = (TreeTableType)SiteContext.Current.Type;
        public TreeTableType TreeType 
        {
            get { return this._type; }
            set { this._type = value; } 
        }

        private int depth = -1;
        public int Depth
        {
            get { return depth; }
            set 
            {
                depth = value; 
            }
        }

        public bool IsOnlyEnable { get; set; }

        protected override string DefaultSkinFilename
        {
            get { return "TreeView/TreeList.ascx"; }
        }
    }
}
